package com.education.business.service.education;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.education.business.mapper.education.GradeInfoMapper;
import com.education.business.service.BaseService;
import com.education.common.utils.FileUtil;
import com.education.model.entity.GradeInfo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zengjintao
 * @version 1.0
 * @create_at 2020/11/19 13:31
 */
@Service
public class GradeInfoService extends BaseService<GradeInfoMapper, GradeInfo> {
    /**
     * 根据考试任务查询
     * 读取并写入json文件
     * @param testPaperArray
     * @return
     */
    public GradeInfo gradeInfoById(JSONArray testPaperArray){
        List<GradeInfo> gradeInfoArrayList = new ArrayList<>();
        GradeInfo gradeInfo = new GradeInfo();
        for(int i=0;i<testPaperArray.size();i++){
            JSONObject testPaper = JSONObject.parseObject(testPaperArray.getString(i));
            gradeInfo = baseMapper.GradeInfoById(testPaper.getInteger("id"));
            gradeInfoArrayList.add(gradeInfo);
        }
        FileUtil.WriteFile("gradeInfo"+".json",FileUtil.tojson(gradeInfoArrayList));
        return gradeInfo;
    }
    public int saveAll(GradeInfo gradeInfo){
        return baseMapper.saveAll(gradeInfo);
    }

}
